<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>Spring Data Neo4j | xlaser&#39;s blog</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="introduction整合spring,neo4j :  Spring Boot, Spring Data, and Neo4j.    stack 应用: Spring-Boot   Web框架: Spring-Boot , Spring-WebMVC, Spring-Data-Rest  持久层: Spring-Data-Neo4j  数据库: Neo4j  前端: jquery, boo">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring Data Neo4j">
<meta property="og:url" content="http://yoursite.com/2018/09/25/Spring Data Neo4j/index.html">
<meta property="og:site_name" content="xlaser&#39;s blog">
<meta property="og:description" content="introduction整合spring,neo4j :  Spring Boot, Spring Data, and Neo4j.    stack 应用: Spring-Boot   Web框架: Spring-Boot , Spring-WebMVC, Spring-Data-Rest  持久层: Spring-Data-Neo4j  数据库: Neo4j  前端: jquery, boo">
<meta property="og:locale" content="default">
<meta property="og:updated_time" content="2018-09-26T11:32:41.993Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Spring Data Neo4j">
<meta name="twitter:description" content="introduction整合spring,neo4j :  Spring Boot, Spring Data, and Neo4j.    stack 应用: Spring-Boot   Web框架: Spring-Boot , Spring-WebMVC, Spring-Data-Rest  持久层: Spring-Data-Neo4j  数据库: Neo4j  前端: jquery, boo">
  
    <link rel="alternate" href="/atom.xml" title="xlaser&#39;s blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link rel="stylesheet" href="/css/style.css">
</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">xlaser&#39;s blog</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">welcome</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-Spring Data Neo4j" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2018/09/25/Spring Data Neo4j/" class="article-date">
  <time datetime="2018-09-25T00:55:29.000Z" itemprop="datePublished">2018-09-25</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/neo4j/">neo4j</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Spring Data Neo4j
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <ul>
<li><h4 id="introduction"><a href="#introduction" class="headerlink" title="introduction"></a>introduction</h4><p>整合spring,neo4j :  Spring Boot, Spring Data, and Neo4j.</p>
</li>
</ul>
<ul>
<li><h4 id="stack"><a href="#stack" class="headerlink" title="stack"></a>stack</h4><ol>
<li><p>应用: Spring-Boot </p>
</li>
<li><p>Web框架: Spring-Boot , Spring-WebMVC, Spring-Data-Rest</p>
</li>
<li><p>持久层: Spring-Data-Neo4j</p>
</li>
<li><p>数据库: Neo4j</p>
</li>
<li><p>前端: jquery, bootstrap, d3.js</p>
</li>
</ol>
</li>
</ul>
<ul>
<li><h4 id="mvn"><a href="#mvn" class="headerlink" title="mvn"></a>mvn</h4><p>spring-boot(major):</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span><br><span class="line">    &lt;artifactId&gt;spring-boot-starter-data-neo4j&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>
<p>neo4j(major):</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">   &lt;groupId&gt;org.neo4j&lt;/groupId&gt;</span><br><span class="line">   &lt;artifactId&gt;neo4j&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>
<p> driver(major):</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;dependency&gt;</span><br><span class="line">   &lt;groupId&gt;org.neo4j&lt;/groupId&gt;</span><br><span class="line">   &lt;artifactId&gt;neo4j-ogm-bolt-driver&lt;/artifactId&gt;</span><br><span class="line">&lt;/dependency&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><h4 id="structure"><a href="#structure" class="headerlink" title="structure"></a>structure</h4><ol>
<li><p>controller </p>
<ul>
<li><p>RestController调用service层</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">public class MovieController</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>service</p>
<ul>
<li><p>Service调用repo层</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">public class MovieService</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>repository</p>
<ul>
<li><p>Neo4j内部类jpa的语法实现</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">public interface MovieRepository extends Neo4jRepository&lt;Movie, Long&gt;</span><br></pre></td></tr></table></figure>
</li>
<li><p>自动实现构建单表语句</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Movie findByTitle(@Param(&quot;title&quot;) String title)</span><br></pre></td></tr></table></figure>
</li>
<li><p>手动定义cypher语句</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">@Query(&quot;MATCH (m:Movie)&lt;-[r:ACTED_IN]-(a:Person) RETURN m,r,a LIMIT limit&#125;&quot;)</span><br><span class="line">Collection&lt;Movie&gt; graph(@Param(&quot;limit&quot;) int limit);</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li><p>entity</p>
<ul>
<li><p>Node节点</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">@NodeEntity</span><br><span class="line">public class Movie</span><br></pre></td></tr></table></figure>
</li>
<li><p>RelationshipEntity关系</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">@RelationshipEntity</span><br><span class="line">public class Role</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
</ol>
</li>
<li><h4 id="run"><a href="#run" class="headerlink" title="run"></a>run</h4><ol>
<li>spring: run application</li>
<li>mvn:  mvn spring-boot:run</li>
<li>访问定义端口的浏览器页面(localhost:8080)</li>
</ol>
</li>
</ul>
<ul>
<li><h4 id="end"><a href="#end" class="headerlink" title="end"></a>end</h4><ol>
<li>通过spring-data框架进行简单整合neo4j</li>
<li>整体保持主流rest风格</li>
<li>持久层通过neo4j提供的ogm相关实现java到graph数据库的映射关系</li>
</ol>
</li>
</ul>
<ul>
<li><h4 id="question"><a href="#question" class="headerlink" title="question"></a>question</h4><ol>
<li>分页相关</li>
<li>复杂cypher语句</li>
<li>前端d3格式</li>
</ol>
</li>
</ul>
<p>​     </p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2018/09/25/Spring Data Neo4j/" data-id="cjmj2t5lg0001r4hjo30rp0zg" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2018/09/25/Introduction for Neo4j/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          A brief introduction for Neo4j
        
      </div>
    </a>
  
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/neo4j/">neo4j</a></li></ul>
    </div>
  </div>


  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2018/09/">September 2018</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2018/09/25/Introduction for Neo4j/">A brief introduction for Neo4j</a>
          </li>
        
          <li>
            <a href="/2018/09/25/Spring Data Neo4j/">Spring Data Neo4j</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2018 Elijah.D<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/script.js"></script>



  </div>
</body>
</html>